package com.lmiot.xyclick.Method;

import android.content.Context;
import android.content.res.Resources;
import android.util.TypedValue;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.TextView;
import com.lmiot.xyclick.App.MyApp;
import com.lmiot.xyclick.Bean.InitFloatBean;
import com.lkx.liandianqinew.R;
import com.lmiot.xyclick.Util.ClickUtils;
import com.lmiot.xyclick.Util.FloatManager;
import com.lmiot.xyclick.View.SwipeView;
import com.xiaoyi.intentsdklibrary.SDK.Action.ActionNormalSDK;
import com.yhao.floatwindow.FloatWindow;
import com.yhao.floatwindow.MoveType;

import java.util.Timer;
import java.util.TimerTask;

public class ParamUtils {
    private static final String TAG = "ParamUtils";
    private static final ParamUtils ourInstance = new ParamUtils();
    private TimerTask mTask;
    private Timer mTimer;

    public interface OnSwipePlusListener {
        void result(boolean z, int i, int i2, int i3, int i4);
    }

    public static ParamUtils getInstance() {
        return ourInstance;
    }

    private ParamUtils() {
    }

    public void addSwipeView(final OnSwipePlusListener onSwipePlusListener) {
        try {
            if (FloatWindow.get("swipeView") != null) {
                FloatWindow.destroy("swipeView");
            }
            final View inflate = View.inflate(MyApp.getContext(), R.layout.layout_swipe_plus, null);
            TextView textView = (TextView) inflate.findViewById(R.id.id_cancel);
            TextView textView2 = (TextView) inflate.findViewById(R.id.id_sure);
            TextView textView3 = (TextView) inflate.findViewById(R.id.id_left);
            TextView textView4 = (TextView) inflate.findViewById(R.id.id_right);
            TextView textView5 = (TextView) inflate.findViewById(R.id.id_up);
            TextView textView6 = (TextView) inflate.findViewById(R.id.id_down);
            final SwipeView swipeView = (SwipeView) inflate.findViewById(R.id.id_swipe_view);
            if (ActionNormalSDK.getInstance().isScreenPortrait(MyApp.getContext())) {
                FloatWindow.with(MyApp.getContext()).setView(inflate).setTag("swipeView").setWidth(MyApp.mWidth).setHeight(MyApp.mHeight).setMoveType(MoveType.inactive).setDesktopShow(true).setMoveStyle(500, new AccelerateInterpolator()).build();
            } else {
                FloatWindow.with(MyApp.getContext()).setView(inflate).setTag("swipeView").setWidth(MyApp.mHeight + getNavigationBarHeight(MyApp.getContext())).setHeight(MyApp.mWidth).setMoveType(1).setDesktopShow(true).setMoveStyle(500, new AccelerateInterpolator()).build();
            }
            setClick(textView3, "left", swipeView);
            setClick(textView4, "right", swipeView);
            setClick(textView5, "up", swipeView);
            setClick(textView6, "down", swipeView);
            textView.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Method.ParamUtils.AnonymousClass1 */

                public void onClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    inflate.setVisibility(View.GONE);
                    if (onSwipePlusListener != null) {
                        onSwipePlusListener.result(false, 0, 0, 0, 0);
                    }
                    FloatManager.hide(InitFloatBean.FloatType.swipPlus);
                }
            });
            textView2.setOnClickListener(new View.OnClickListener() {
                /* class com.lmiot.xyclick.Method.ParamUtils.AnonymousClass2 */

                public void onClick(View view) {
                    ClickUtils.onlyVibrate(MyApp.getContext());
                    inflate.setVisibility(View.GONE);
                    int cententX0 = swipeView.getCententX0();
                    int cententX1 = swipeView.getCententX1();
                    int cententY0 = swipeView.getCententY0();
                    int cententY1 = swipeView.getCententY1();
                    if (ActionNormalSDK.getInstance().isScreenPortrait(MyApp.getContext())) {
                        cententY0 += ParamUtils.this.getStatusBarHeight(MyApp.getContext());
                        cententY1 += ParamUtils.this.getStatusBarHeight(MyApp.getContext());
                    } else {
                        cententX0 += ParamUtils.this.getStatusBarHeight(MyApp.getContext());
                        cententX1 += ParamUtils.this.getStatusBarHeight(MyApp.getContext());
                    }
                    if (onSwipePlusListener != null) {
                        onSwipePlusListener.result(true, cententX0, cententY0, cententX1, cententY1);
                    }
                    FloatManager.hide(InitFloatBean.FloatType.swipPlus);
                }
            });
            FloatManager.show(InitFloatBean.FloatType.swipPlus);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setClick(TextView textView, final String str, final SwipeView swipeView) {
        textView.setOnClickListener(new View.OnClickListener() {
            /* class com.lmiot.xyclick.Method.ParamUtils.AnonymousClass3 */

            public void onClick(View view) {
                swipeView.change(str);
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private int getStatusBarHeight(Context context) {
        int identifier = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (identifier > 0) {
            return context.getResources().getDimensionPixelSize(identifier);
        }
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 24, Resources.getSystem().getDisplayMetrics());
    }

    private int getNavigationBarHeight(Context context) {
        Resources resources = context.getResources();
        return resources.getDimensionPixelSize(resources.getIdentifier("navigation_bar_height", "dimen", "android"));
    }
}
